home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 647 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 76623,2065@compuserve.com  (Bobby Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Trig functions
  5. Date: 5 Jan 1996 15:15:45 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4cjfb1$fco@dub-news-svc-4.compuserve.com>
  8. References: <4ch9ka$4pc@felix.junction.net>
  9. Reply-To: 76623,2065@compuserve.com (Bobby Martin)
  10. NNTP-Posting-Host: dd24-036.compuserve.com
  11. X-Newsreader: IBM NewsReader/2 v1.03
  12.  
  13. In <4ch9ka$4pc@felix.junction.net>, heppner@portage.net (Donald Heppner) writes:
  14. >I need to have a few trig functions in my C++ program.  I have found 
  15. >some trig functions, but for some reason, they give the wrong answer
  16. >(Maybe a different kind of trig).  I need tan, cos, sin, and all of these
  17. >functions to the power of negative one.  I need them to give me the same 
  18. >answer as a calculator would.
  19. >
  20. >Thanks
  21. >Donald
  22. The problem is probably that the standard C library trig functions require
  23. the angle in radians and you're giving degrees.  Just multiply the number
  24. you're giving the function by pi/180, where pi is approximately 3.14159.
  25. i.e. instead of
  26. x = pow( sin( 3*b+30 ), -1 );
  27. use this
  28. const float pi=3.14159
  29. ..
  30. x = pow( sin( (3*b+30) * pi / 180 ), -1 );
  31.  
  32.  
  33. Hope that helps.
  34.